package com.itheima.solr;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.junit.Test;

import java.util.List;

public class TestQueryBean {
    @Test
    public void testQueryBean() throws SolrServerException {
        //连接solr服务器
        SolrServer solrServer =  new HttpSolrServer("http://localhost:8080/solr/core1");
        //创建查询对象
        SolrQuery solrQuery = new SolrQuery("title:手机");
        //发送web请求
        QueryResponse response = solrServer.query(solrQuery);
        //获取结果集
        List<Item> list = response.getBeans(Item.class);
        for (Item item : list) {
            System.out.println(item.getId());
            System.out.println(item.getTitle());
            System.out.println(item.getPrice());
        }
    }
}
